<?php
namespace Home\Controller;

use Think\Controller;

class IndexController extends UserBaseController
{
    public function index()
    {
        $this->show('<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;font-size:24px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px } a,a:hover{color:blue;}</style><div style="padding: 24px 48px;"> <h1>:)</h1><p>欢迎使用 <b>ThinkPHP</b>！</p><br/>版本 V{$Think.version}</div><script type="text/javascript" src="http://ad.topthink.com/Public/static/client.js"></script><thinkad id="ad_55e75dfae343f5a1"></thinkad><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script>','utf-8');
    }

    /**
     * 反馈接口
     */
    public function feedback(){
        $uid = $this->uid;
        $content = $_REQUEST['content'];
        $type = intval($_REQUEST['type']); //0表示建议，1表示投诉
        $ip = $_SERVER['REMOTE_ADDR'];
        if(!in_array($content,array(0,1))){
            returnMobileJson(201,'类型错误');
        }
        if(!$content){
            returnMobileJson(202,'内容不能为空');
        }

        $map['ip'] = $ip;
        $map['ctime'] = array('gt',time() - 3600);
        $count = D('feedback')->where($map)->count();
        if($count > 10){
            returnMobileJson(204,'操作太频繁');
        }

        $data['uid']= $uid ? $uid : 0;
        $data['ctime'] = time();
        $data['content'] = $content;
        $data['type'] = $type;
        $data['ip'] = $ip;
        $res = D('feedback')->add($data);
        if($res){
            returnMobileJson(200,'添加成功');
        }else{
            returnMobileJson(203,'添加失败');
        }
    }

    /**
     * 申请滴滴师傅和城市合伙人
     */
    public function apply_account(){
        $data['username'] = $_REQUEST['username'];
        $data['sex'] = intval($_REQUEST['sex']);//2表示女生，1表示男生
        $data['city'] = $_REQUEST['city'];
        $data['phone'] = $_REQUEST['phone'];
        $data['wx_access'] = $_REQUEST['wx_access'];
        $data['introduce'] = $_REQUEST['introduce'];
        $data['idcard'] = $_REQUEST['idcard'];
        $data['idcard_front'] = $_REQUEST['idcard_front'];
        $data['idcard_contrary'] = $_REQUEST['idcard_contrary'];
        $data['city_id'] = $_REQUEST['city_id'];//城市 id；
        $data['type'] = $_REQUEST['type'];//1表示滴滴工程师，2表示城市合伙人
        $data['m_date'] =  date('Y-m-d H:i:s',time());
        foreach($data as $key => $v){
            if(!$v){
                returnMobileJson(201,'参数错误',$key);
            }
        }

        if($data['type'] == 1){
            if(!$_REQUEST['working_age']){
                returnMobileJson(201,'参数错误','working_age');
            }
            $data['working_age'] = $_REQUEST['working_age'];
        }elseif($data['type'] == 2){
            if(!$_REQUEST['business_license']){
                returnMobileJson(201,'参数错误','business_license');
            }
            $data['business_license'] = $_REQUEST['business_license'];
        }elseif($data['type']==3){
            if(!$_REQUEST['store_photo']){
                returnMobileJson(201,'参数错误','store_photo');
            }
            $data['store_photo'] = $_REQUEST['store_photo'];
            $data['business_license'] = $_REQUEST['business_license'];
        }
        $data['ctime'] = time();
        $res = D('apply_account')->add($data);
        if($res){
            returnMobileJson(200,'添加成功');
        }else{
            returnMobileJson(202,'添加失败');
        }

    }


    public function get_apply_account(){
        $current = $_REQUEST['page']?$_REQUEST['page']:1;
        $condition = array();
        if($_REQUEST['type']){
            $condition['type'] = $_REQUEST['type'];
        }
        $apply_account_db = M('apply_account');
        $data = $apply_account_db->where($condition)->order('id desc')->page($current,10)->select();
        returnMobileJson(200,'数据获取成功',$data);
    }





    public function set_index_banner(){
        S('banner_json',$_REQUEST['banner_json']);
        returnMobileJson(200,'数据存放成功');
    }


    public function get_index_banner(){
        $json = S('banner_json');
        $arr =  json_decode($json);
        returnMobileJson(200,'数据获取成功',$arr);
    }

    /*
     * CREATE TABLE `mp_apply_account` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(20) DEFAULT '' COMMENT '申请名称',
  `sex` int(2) DEFAULT '0' COMMENT '0表示女生，1表示男生',
  `city` int(11) DEFAULT '0' COMMENT '城市id',
  `phone` varchar(20) DEFAULT '' COMMENT '手机号码',
  `wx_access` varchar(40) DEFAULT '' COMMENT '微信账号',
  `introduce` varchar(255) DEFAULT '' COMMENT '描述',
  `idcard` varchar(20) DEFAULT '' COMMENT '身份证号码',
  `idcard_front` varchar(40) DEFAULT '' COMMENT '身份证正面',
  `idcard_contrary` varchar(40) DEFAULT '' COMMENT '身份证正面',
  `type` int(2) DEFAULT '0' COMMENT '0表示滴滴工程师，1表示城市合伙人',
  `ctime` int(11) DEFAULT '0' COMMENT '创建时间',
  `status` int(11) DEFAULT '0' COMMENT '0表示提交，1表示已处理',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;*/


}